package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.activity.ActDetailActivity;
import com.example.a14110100409.yuejiandemo.javabean.ListResult;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


/**
 * Created by Administrator on 2017/9/30 0030.
 */

public class ActAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ListResult> list;
    private  View view;
    public ActAdapter(Context c,List<ListResult> list)
    {
        this.context=c;
        this.list=list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        view=LayoutInflater.from(context).inflate(R.layout.item_of_activity,viewGroup,false);
        ActViewHolder viewHolder=new ActViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ActViewHolder actViewHolder=(ActViewHolder) viewHolder;
        ;
        final ListResult result=list.get(i);
        final String address="http://172.24.10.175/workout/Uploads/"+result.getThumb();
        actViewHolder.num.setText("报名人数："+result.getHits());
        actViewHolder.title.setText("活动名称："+result.getActivity_name());
        Picasso.with(context).load(address).into(((ActViewHolder) viewHolder).pic);
        ((ActViewHolder) viewHolder).item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, ActDetailActivity.class);
                intent.putExtra("act_id",result.getId());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class  ActViewHolder extends RecyclerView.ViewHolder
    {
        ImageView pic;
        TextView title;
        TextView num;
        LinearLayout item;
        public ActViewHolder(View itemView) {
            super(itemView);
            item=(LinearLayout)itemView.findViewById(R.id.item_of_activity);
            pic=(ImageView) itemView.findViewById(R.id.act_list_pic);
            title=(TextView) itemView.findViewById(R.id.act_list_title);
            num=(TextView) itemView.findViewById(R.id.act_list_num);
        }
    }
}

